package cloud.lysky.java.on.enumclass;

import java.util.Random;
import java.util.function.Supplier;

/**
 * @author luoly
 * @describe
 * @date 2023/3/3 12:52
 **/
//枚举类实现接口
enum CartoonCharacter implements Supplier<CartoonCharacter>{
    //声明一些卡通角色
    XIONGDA, //熊大
    XIONGER, //熊二
    GUANGTOUQIANG,//光头强
    AOTEMAN, //奥特曼
    HUITAILANG,//灰太狼
    BAOLONGSHEN;//暴龙神

    //随机置数器
    private Random rand = new Random(47);

    //因为实现Supplier接口，所以要重写get方法
    @Override
    public CartoonCharacter get() {
        // 随机返回一个枚举值
        // ps: values方法由编译器生成
        return values()[rand.nextInt(values().length)];
    }
}

public class EnumImplementation {
    public static void main(String[] args) {
        //选择任一实例：
        CartoonCharacter dragon = CartoonCharacter.BAOLONGSHEN;
        for (int i = 0; i < 10; i++) {
            printNext(dragon);
        }
    }
    public static <T> void printNext(Supplier<T> arg){
        System.out.print(arg.get() + ",");
    }
}
